<template>
	<view class="address-container">
		<view class="address-choose-box" v-if="JSON.stringify(address)==='{}' " @click="chooseAddress">
			<button type="primary" size="mini" >请选择收货地址+</button>
		</view>
		
		<view class="address-content" v-else @click="chooseAddress">
			<view class="row1">
				<view class="row1-left">
					<view class="username">收货人:{{address.userName}}</view>
				</view>
				
				<view class="row1-right">
					<view class="phone">电话:{{address.telNumber}}</view>
					<uni-icons class="right-arrow" type="forward" size="20"></uni-icons>
				</view>
			</view>
			
			<view class="row2">
				 <view class="row-left">收货地址：</view>
				 <view class="row-right">{{addstr}}</view>
			</view>
		</view>
			
		<image src="/static/cart_border@2x.png" class="address-border"></image>
	</view>
	
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		
		name:"my-address",
		data() {
			return {
			};
		},
		computed:{
			...mapState('m_user',['address']),
			...mapGetters('m_user',['addstr'])
		}
		,
		methods:{
		...mapMutations('m_user',['updateAddress']),
		async	chooseAddress(){
					const [err,succ] = await uni.chooseAddress().catch(err=>err)
						if(err==null && succ.errMsg == 'chooseAddress:ok')
						{
							this.updateAddress(succ)
						}
			},
		async	reAuth(){
			const val =  await uni.showModal({
					content:"检测到您没有打开地址权限，是否去设置打开？",
					confirmText:"确认",
					cancelText:"取消"
				})
			}
		}
	}
</script>

<style lang="scss">
	.address-container{
		margin: 10px 0;
		.address-choose-box{
			display: flex;
			align-items: center;
			justify-content: center;
			height: 80px;
		}
			.address-border{
				display: block;
				width: 100%;
				height: 5px;
			}
			
			.address-content{
				font-size: 14px;
				padding: 0 0 0 10px;
				.row1{
					display: flex;
					justify-content: space-between;
					.row1-right{
						display: flex;
						.right-arrow{
							margin-left: 5px;
						}
					}
				}
				.row2{
					font-size: 12px;
					display: flex;
					align-items: center;
					line-height: 14px;
					margin: 10px 0;
					.row-left{
						white-space: nowrap;
					}
				}
			}
	}

</style>